<script setup lang="ts">

import RoomStatus from './components/RoomStatus.vue'
import RoomAction from './components/RoomAction.vue'
import RoomMessage from './components/RoomMessage.vue'
import { ref, nextTick, provide } from 'vue'
import { knowledgechat } from '@/services/consult'


const list = ref([{"id":1,'msgType':1,'from':'1','fromAvatar':'2','to':'1','toAvatar':'1','createTime':'2020','msg':{'content':'亲爱的患者，我是智能助理，您有什么问题都可以咨询我'}}])
const msg = ref('')
// 下拉刷新
const loading = ref(false)
const onSendText = (text: string) => {
  list.value.push({"id":1,'msgType':1,'from':'1','fromAvatar':'2','to':'1','toAvatar':'1','createTime':'2020','msg':{'content':text}})
  knowledgechat(text).then((res) => {
      list.value?.push({"id":1,'msgType':1,'from':'1','fromAvatar':'2','to':'1','toAvatar':'1','createTime':'2020','msg':{'content':res.data}})
  })
  .catch(() => {

  })

}
const onRefresh = () => {}
</script>

<template>
    <div class="room-page">
      <cp-nav-bar title="智能问诊"></cp-nav-bar>
      <van-pull-refresh v-model="loading" @refresh="onRefresh">
        <!-- 消息 -->
        <room-message
          v-for="item in list"
          :key="item.id"
          :item="item"
        ></room-message>
      </van-pull-refresh>
      <!-- 操作栏 -->
      <room-action
        @send-text="onSendText"       
      ></room-action>
    </div>
  </template>
  
  <style lang="scss" scoped>
  .room-page {
    padding-top: 90px;
    padding-bottom: 60px;
    min-height: 100vh;
    box-sizing: border-box;
    background-color: var(--cp-bg);
    .van-pull-refresh {
      width: 100%;
      min-height: calc(100vh - 150px);
    }
    .item {
      > p {
        color: var(--cp-text3);
        padding: 15px 0;
      }
    }
  }
  </style>